package cn.apelx.shardingjdbc.repository;

import cn.apelx.shardingjdbc.domain.OrderDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 订单明细
 *
 * @author apelx
 * @since 2022-05-13
 */
@Repository
public interface OrderDetailRepository extends JpaRepository<OrderDetail, Integer>, JpaSpecificationExecutor<OrderDetail> {

    OrderDetail getById(Integer id);

    List<OrderDetail> findByIdIn(List<Integer> ids);

    @Query(value = "select * from t_order_detail detail " +
            " left join t_order tor on detail.order_id = tor.id " +
            " where detail.id in (?1)", nativeQuery = true)
    List<OrderDetail> findJoin(List<Integer> ids);
}
